package org.adit.spring.hibernate.util;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;

public class CsvUtil {
	String outputFile = "users.csv";
	// before we open the file check to see if it already exists
	boolean alreadyExists = new File(outputFile).exists();
		private void csvWriter(FileWriter fileWriter, char c) {
			String outputFile = "users.csv";
			
			// before we open the file check to see if it already exists
			boolean alreadyExists = new File(outputFile).exists();
				
			try {
				// use FileWriter constructor that specifies open for appending
				CsvWriter csvOutput = new CsvWriter(new FileWriter(outputFile, true), ',');
				
				// if the file didn't already exist then we need to write out the header line
				if (!alreadyExists)
				{
					csvOutput.write("id");
					csvOutput.write("name");
					csvOutput.endRecord();
				}
				// else assume that the file already has the correct header line
				
				// write out a few records
				csvOutput.write("1");
				csvOutput.write("Bruce");
				csvOutput.endRecord();
				
				csvOutput.write("2");
				csvOutput.write("John");
				csvOutput.endRecord();
				
				csvOutput.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
			
		}
}